local panel             = UIBase.New(PanelResNames.UILanguageSetting)

local m_language_list   = {}
local m_select_index    = nil
local m_lantype = nil

function panel.Init(data, _goFunc)
    UIBase.Init(panel)
end

function panel:OnCreate()
    self:RegisterOnClick(self:GetChild("Btn_BgClose"),  self.OnClick_closePanel)
    self:RegisterOnClick(self:GetChild("Btn_Cancel"),  self.OnClick_closePanel)
    self:RegisterOnClick(self:GetChild("Btn_Confirm"),  self.OnClick_confirm)
    self:RegisterOnClick(self:GetChild("Btn_Confirm2"),  self.OnClick_download)
    self:RegisterOnClick(self:GetChild("Btn_Cancel"),  self.OnClick_cancel)

    self.ctr_download   = self:GetController("Confirm")
    self.scroll_list    = self:GetChild("List_Language")
    self.txt_download   = self:GetChild("Text_Download")
    self.txt_languagetype = self:GetChild("Text_LanguageTips")

    m_language_list     = {{type = EnumConst.LanguageType.CN, name = "中文简体"},{type = EnumConst.LanguageType.CT, name = "繁体中文"}}

    m_lantype = UnityEngine.PlayerPrefs.GetInt("Language_Type", 0)
    self.scroll_list.itemRenderer = panel.itemRender
    self.scroll_list.numItems = #m_language_list

    
end

function panel:OnDisable()
    
end

function panel:OnDestroy()
    
end

function panel.itemRender(index, obj)
    local txt_lan = obj:GetChild("Text_Language")
    local ctr_btn = obj:GetController("button")

    -- dump(m_lantype)
    -- if m_lantype == 3 and index == 1 then
    --     ctr_btn.selectedIndex = 1
    -- elseif m_lantype == index then
    --     ctr_btn.selectedIndex = 1
    -- else
    --     ctr_btn.selectedIndex = 0
    -- end

    txt_lan.text = m_language_list[index + 1].name

    obj.onClick:Add(function()
        m_select_index = index
        if index == 1 then
            LanguageManager.SetSelectType(3)
        else
            LanguageManager.SetSelectType(0)
        end
    end)
end

function panel:OnClick_closePanel()
    closeUI(PanelResNames.UILanguageSetting)
end

function panel.ShowDownloadTips(size)
    self.ctr_download.selectedIndex = 1
    self.txt_download.text = string.format("(预估下载资源：%.1fMB)", size/1024)
end

function panel:OnClick_confirm()
    if m_select_index == 1 then
        if m_lantype ~= EnumConst.LanguageType.CT then
            LanguageMgr:ShowAssetsSizeTip(3)
        else

        end
    elseif m_select_index == 0 then
        if m_lantype ~= EnumConst.LanguageType.CN then
            LanguageManager.SetSelectType(0)
            LanguageManager.DoChangeLanguage()
        end
    end
end

function panel:OnClick_cancel()
    self.ctr_download.selectedIndex = 0
end

function panel:OnClick_download()
    if m_select_index == 1 then
        
        
    else
        LanguageMgr:ChangeLanguage(0)
    end
end

return panel